<template>
  <el-pagination
    :current-page.sync="currentPage"
    :page-size.sync="pageSize"
    :page-sizes="[10, 20, 50]"
    :total="total"
    background
    layout="total, sizes, prev, pager, next, jumper"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script>
export default {
  name: 'Pagination',
  props: {
    page: { type: Number, default: 1 }, // 当前页
    rows: { type: Number, default: 10 }, // 显示条数
    total: { type: Number, required: true } // 总条数
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.rows
      },
      set(val) {
        this.$emit('update:rows', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(7, val)
      this.$emit('pagination', { page: this.currentPage, rows: val })
    },
    handleCurrentChange(val) {
      console.log(8, val)
      this.$emit('pagination', { page: val, rows: this.pageSize })
    }
  }
}
</script>

<style scoped>
.el-pagination {
  padding: 0;
}
</style>
